package cn.edu.lingnan.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class NotificationService {
    @Autowired
    private SimpMessagingTemplate simpMessagingTemplate;

    @Async
    public void sendExamNotifications(List<Integer> userIdList) {
        for (Integer userId : userIdList) {
            log.info("sendExamNotificationsAsync userId:{}, message:{}", userId, "你有一场考试即将开始，请准时参加！");
            simpMessagingTemplate.convertAndSendToUser(
                    String.valueOf(userId),
                    "/queue/notifications",
                    "{\"message\":\"你有一场考试即将开始，请准时参加！\"}"
            );
        }
    }
}
